<template>
	<view>

		<view v-if="orderList.length > 0" style="padding-bottom: 20upx;">

			<view class="item1" v-for="(item, index) in orderList" :key="index">

				<view class="title-wrap">

					<text class="title" v-if='item.rentType === 1'>经租</text>
					<text class="title" v-if='item.rentType === 2'>以租代购</text>
					<text class="title" v-if='item.rentType === 3'>展示车</text>
					<text class="title" v-if='item.rentType === 4'>试用车</text>
					<text class="title" v-if='item.rentType === 5'>融租</text>
					<text class="title" v-if='item.rentType === 6'>直购</text>

					<view class="title-warn">
						{{ item.flowStatusName }}
					</view>
				</view>

				<u-line color="#efefef" dashed margin="0 0 15px"></u-line>
				
				<view class="text-line1">
					<text class="text-name">经销商:</text>
					<text class="text-value">{{filterNull(item.tenantName)}}</text>
				</view>
				
				<view class="text-line1">
					<text class="text-name">车辆订单号:</text>
					<text class="text-value">{{filterNull(item.orderCarCode)}}</text>
				</view>


				<view class="text-line1" v-if="item.rentType!=6">
					<text class="text-name">租期:</text>
					<text class="text-value"
						style="flex-grow: 0;">{{filterNull(item.timeStartRent)}}至{{filterNull(item.timeFinishRent)}}</text>

					<text class="tenacy">{{filterNull(item.tenancy)}}期</text>
				</view>

				<view class="text-line1">
					<text class="text-name">车牌号:</text>
					<text class="text-value">{{filterNull(item.carNo)}}</text>
				</view>

				<view class="text-line1">
					<text class="text-name">品牌/车系/车型:</text>
					<text
						class="text-value">{{filterNull(item.brandName)}}/{{filterNull(item.seriesName)}}/{{filterNull(item.modelName)}}</text>
				</view>


				<view class="text-line1" v-if="item.rentType==5">
					<text class="text-name">金融公司:</text>
					<text class="text-value">{{filterNull(item.financeCompanyName)}}</text>
				</view>

				<view class="fee-list" style="margin-top:16px" @click.stop="itemClick(item)">
					
					<view class="flex">
						<view v-for="(childitem, childindex) in item.moneyPlanList"
							:key="childitem.moneyDesc">
							<text class="text-name" >{{childitem.moneyDesc}}:</text>
							<text class="text-value">￥{{childitem.moneyAmount}}</text>
						</view>
					</view>
					
				<!-- 	<u-icon name="arrow-right"></u-icon> -->
				</view>
				<!-- #ifndef H5 -->
				<view class="own-money" v-if="item.uncollectedAmountDesc">
					{{filterNull(item.uncollectedAmountDesc)}}
				</view>
				<!-- #endif -->
				
				<!-- #ifdef H5 -->
				<view class="title-wrap" style="justify-content: space-between;margin-bottom: 10upx;margin-top:20px">
					<view v-if="item.uncollectedAmountDesc" style='color:#FF6A15;font-size: 28upx;'>
						{{filterNull(item.uncollectedAmountDesc)}}
					</view>
					<view v-else>
						
					</view>
					<view class='btn_sty'  @click.stop="itemClick(item)">
						详情
					</view>
				</view>
				<!-- #endif -->
				<!-- #ifndef H5 -->
				<view class="title-wrap" style="justify-content: flex-end;margin-bottom: 10upx;margin-top:20px">
					
					<view class='btn_sty'  @click.stop="itemClick(item)">
						详情
					</view>
					<!-- <view v-if="isEnv!=3 && item.uncollectedAmount>0" class="btn-detail" style="background-color: #E04B28;"
						@click.stop="itemClick(item)">
						立即支付
					</view> -->
				</view>
				<!-- #endif -->
				<!-- 欠款提醒 -->
				<view class="own-money" v-if='item.receivablesDesc'>
					<view style='width:32upx;height: 32upx;'>
						<image class="close-img" src="../../../static/message_icon_tips@2x.png"></image>
					</view>
					
					<text style='font-size: 24upx;color:#173B42'>
						{{item.receivablesDesc}}
					</text>	
				</view>
				<!-- 替换车提醒 -->
				<view class="own-money " v-if='item.swappedOrderCarDesc'>
					<view style='width:32upx;height: 32upx;'>
						<image class="close-img" src="../../../static/message_icon_tips@2x.png"></image>
					</view>
					
					<text >
						{{item.swappedOrderCarDesc}}
					</text>	
				</view>
				<!-- 被替换车提醒 -->
				<view class="own-money " v-if='item.swopOrderCarDesc'>
					<view style='width:32upx;height: 32upx;'>
						<image class="close-img" src="../../../static/message_icon_tips@2x.png"></image>
					</view>
					
					<text >
						{{item.swopOrderCarDesc}}
					</text>	
				</view>
				<!-- 备用车 -->
				<view class="own-money " v-if='item.spareCarDesc'>
					
				{{item.spareCarDesc}}</view>

			</view>

			<u-loadmore class='learMore' :status="loadingStatus" @loadmore="clickloadmore"></u-loadmore>
		</view>
		<view class='learMore' v-else >
			<no-data></no-data>
		</view>
	</view>
</template>

<script>
	import {
		ordercarlist,
		commonenv
	} from '../../../common/api.js';
	import {
		getTokenInfo
	} from '../../../common/apis/home-api.js';

	export default {
		data() {
			return {
				isEnv: 0,
				pageNo: 1,
				loadingStatus: 'loading',
				orderList: []
			}
		},

		onShow() {
			// // #ifdef H5
			// //如果有deptId,不需要再选门店
			// let routes = getCurrentPages()
			// let curParam = routes[0].options
			// if(curParam?.accessToken){
			// 	getTokenInfo({accessToken:accessToken}).then((res)=>{
			// 		if(res){
			// 			this.$store.commit('user/saveAccessToken', res.accessToken);
			// 			this.$store.commit('user/saveUserInfo', res);
			// 			this.pageNo = 1;
			// 			this.getData();
			// 			this.getEnv();
			// 			uni.$on('emit', res=>{
			// 				this.cityName = res
			// 				this.isCity = false
			// 			})
			// 		}
			// 	})
			// }else{
			// 	this.pageNo = 1;
			// 	this.getData();
			// 	this.getEnv();
			// 	uni.$on('emit', res=>{
			// 		this.cityName = res
			// 		this.isCity = false
			// 	})
			// }
			
			
			// // #endif
			
			// #ifndef H5
				this.pageNo = 1;
				this.getData();
				this.getEnv();
			// #endif
		},
		mounted(){
			// #ifdef H5
			uni.showLoading({
			  title: '加载中'
			})
			if(uni.getStorageSync('accessToken')){
				setTimeout(()=>{
					this.pageNo = 1;
					this.getData();
					this.getEnv();
				},1000)
			}
			// #endif
		},
		methods: {
			getEnv(){
				commonenv().then(res=>{
					this.isEnv = res;
				})
			},
			getData() {
				ordercarlist({
					params: {
						pageNo: this.pageNo
					}
				}).then(res => {
					uni.hideLoading()
					if (this.pageNo == 1) {
						this.orderList = [];
						this.pageNo++;
						// uni.stopPullDownRefresh();

						this.loadingStatus = 'loadmore';
					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.pageNo++;

							this.loadingStatus = 'loadmore';
						} else {

							this.loadingStatus = 'nomore';
						}
					}

					if (!uni.$u.test.isEmpty(res)) {
						this.orderList = this.orderList.concat(res);
					}
					
				})
			},

			// pay(item){
			// 	uni.showLoading({
			// 		title: '加载中...',
			// 	})
			// 	uni.$u.http.post('app/pay', {
			// 		type: 1, //{2订单1缴费}
			// 		receivablesId: this.receivablesId, // 缴费id
			// 		orderCarId: '' // 订单id
			// 	}).then(res => {
			// 		uni.hideLoading()
			// 		uni.requestPayment({
			// 			timeStamp: res.timeStamp,
			// 			nonceStr: res.nonceStr,
			// 			package: res.package,
			// 			signType: res.signType,
			// 			paySign: res.paySign,
			// 			success(res) {
			// 				// uni.navigateBack()
			// 				this.pageNo = 1;
			// 				this.getData();
			// 			},
			// 			fail(res) {
			// 				uni.hideLoading()
			// 				uni.showToast({
			// 					title: '支付取消',
			// 					icon: 'none'
			// 				})
			// 			}
			// 		});
			// 	});
			// },

			itemClick(item) {
				uni.navigateTo({
					url: './car-orderdetail?id=' + item.orderCarId
				})
			},

			clickloadmore() {
				this.getData();
				this.showloading = true;
				this.loadingStatus = 'loading';
			},


		},
		onPullDownRefresh() {
			this.pageNo = 1;
			this.getData();
		},

		onReachBottom() {
			this.getData();
			this.showloading = true;
			this.loadingStatus = 'loading';
		}

	}
</script>

<style lang="scss" scoped>

	.learMore{
		margin-bottom: 40upx !important;
	}
	.flex{
		padding:16upx 32upx;
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: space-between;
		width: 100%;
	}
	.item1{
		margin: 32upx;
		background-color: #ffffff;
		border-radius: 8upx;
		padding:32upx
	}
	.text-line1{
		display: flex;
		align-items: center;
		font-size: 24upx;
		color:#666666 ;
		margin-bottom: 16upx;
		.text-value{
			color:#666666 ;
		}
		.text-name{
			color:#666666 ;
		}
		
	}
	.btn_sty{
		border:1px solid #173b42;
		background-color: #ffffff;
		color:#173b42;
		border-radius: 8upx;
		width:120upx;
		height: 64upx;
		line-height: 64upx;
		font-size:28upx;
		text-align: center;
		margin: 8upx;
	}
	.title-wrap {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 0;
	}

	.title {
		width: 100%;
		height: 80upx;
		line-height: 80upx;
		font-size: 32upx;
		color: #000000;
		font-weight: bold;
	}

	.title-warn {
		color: #FF6A15 ;
		white-space: nowrap;
		text-align: center;
		font-size: 28upx;
		line-height: 46upx;
	}

	.tenacy {
		font-size: 20upx;
		color: #173B42 ;
		background-color: #DDEFFE ;
		padding: 4upx 16upx;
		border-radius: 4upx;
		margin-left: 16upx;

	}

	.fee-list {
		@include flex;
		align-items: center;
		justify-content: flex-end;
		background-color:#F8F8F8  ;

		text {
			color: #666666 ;
			font-size: 24upx;
		}


	}

	.own-money {
		display: flex;
		align-items: center;
		justify-content: start;
		color: #173B42 ;
		font-size: 28upx;
		align-self: flex-end;
		margin-top:32upx;
		background-color: rgba(200, 221, 65, 0.15);
		padding:16upx 32upx;
		border-radius: 8upx;
		text{
			margin-left:16upx ;
		}
		.close-img{
			width:100%;
			height: 100%;
		}
	}
</style>
